home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / inkey4c.zip / KEYDEMO.C < prev    next >
C/C++ Source or Header  |  1993-03-17  |  9KB  |  303 lines

  1. /* _______________________________________________________________________  */
  2. /*                         INKEY Test version 1.01                          */
  3. /*                  Copyright 1993 by John H. Traphofner                    */
  4. /* _______________________________________________________________________  */
  5. #include <stdio.h>
  6. #include <conio.h>
  7. #include <dos.h>
  8. #include "inkey.h"    /* If inkey.h header file is not located in your
  9.              default include directory, change this line.       */
  10.  
  11. #define ON  1         /* To make the cursor(ON) and cursor(OFF) readable    */
  12. #define OFF 0
  13.  
  14. void cursor(char toggle);       /* Function to turn cursor on and off       */
  15.  
  16. void status_display();          /* Function to display self-updating status
  17.                    screen for the key toggle switches       */
  18.  
  19. void fkey_music();              /* Function to display menu of function keys
  20.                    for making sounds with F1 - F12          */
  21.  
  22. void psound(int,int);           /* Function to Make sound (freq, length)    */
  23.  
  24. #define SUPERQUICK 16   /* Used to make KEY_WAIT length values more         */
  25. #define QUICK 256       /* readable  With SUPERQUICK, the key better        */
  26. #define NORMAL 1024     /* be there when you ask for it.  With the          */
  27. #define SLOW 2048       /* SLOW, there is little chance of missing it       */
  28. #define FOREVER 0       /* and FOREVER waits and waits and waits...         */
  29.  
  30. int FINISHED =0;        /* Global variable that either of the two main
  31.                functions (status_display) or (fkey_music) can
  32.                set to tell the main routine the user wants to
  33.                end the entire program.                          */
  34.  
  35. /* _______________________________________________________________________  */
  36.  
  37. /*                               MAIN ROUTINE                               */
  38. /* _______________________________________________________________________  */
  39. void main ()
  40. {
  41. cursor(OFF);
  42.     do
  43.     {
  44.     KEY_WAIT=QUICK;
  45.     status_display();                     /* Display key Toggle Status  */
  46.  
  47.     if(FINISHED==0) fkey_music();         /* Display F-key menu if the
  48.                          FINISHED variable is false */
  49.  
  50.     } while ( !FINISHED );
  51.  
  52.  
  53.  
  54. cursor(ON);              /* Restore the cursor before leaving               */
  55. clrscr();                /* and clear the screen                            */
  56.  
  57. return;
  58.  
  59. }
  60. /* _______________________________________________________________________  */
  61.  
  62.  
  63.  
  64.  
  65.  
  66. /* _______________________________________________________________________ */
  67. /* Function to turn cursor on and off   */
  68. /* _______________________________________________________________________ */
  69. void cursor(char toggle)
  70. {
  71. static char c_start;
  72. static char c_end;
  73.  
  74. if(!toggle)
  75.      {
  76.     asm     mov  ah,3               /* Bios call for cursor lines */
  77.     asm     mov  bh,0               /* page 0                     */
  78.     asm     int  10h                /* _CH = begin scan line      */
  79.     c_start = _CH;                  /* _CL = end scan line        */
  80.     c_end   = _CL;                  /* store for the restoring    */
  81.     asm     mov  cl,0               /* end scan                   */
  82.     asm     mov  ch,20              /* before it begins           */
  83.     asm     mov  ah,1               /* set the lines              */
  84.     asm     int  10h                /* and cursor vanishes        */
  85.      }
  86. else
  87.      {
  88.     asm     mov  ch,c_start         /* restore the old scan start */
  89.     asm     mov  cl,c_end           /* and the old scan end       */
  90.     asm     mov  ah,1               /* set the lines              */
  91.     asm     int  10h                /* its BACK ! Cusror is On    */
  92.      }
  93. printf(" \b");
  94. return;
  95. }
  96. /* _______________________________________________________________________ */
  97.  
  98.  
  99. /* _______________________________________________________________________ */
  100. /* Function to make some noise throught the PC Speaker                     */
  101. /* _______________________________________________________________________ */
  102.  
  103. void psound(int xnote, int xtime)
  104. {
  105. int psx;
  106.     sound (xnote);
  107.     delay (xtime-30);
  108.     for(psx=xtime+30;psx>=1;psx--){sound (xnote-1);}
  109.     nosound();
  110.  
  111. return;
  112. }
  113. /* _______________________________________________________________________ */
  114.  
  115. /* _______________________________________________________________________ */
  116. /* Function to display contiually updated toggle key status screen         */
  117. /* _______________________________________________________________________ */
  118. void status_display()
  119. {
  120.  
  121. static int KB101 = 255;
  122.  
  123. if (KB101==255) KB101=inkey(STATUS);
  124.  
  125. clrscr();
  126.  
  127. printf  ("\n\t\t\t╔═════════════════════════════╗");
  128.  
  129. if(KB101)
  130. printf("\n\t\t\t║   Extended  101  keyboard.  ║");
  131. else
  132. printf("\n\t\t\t║     84-Key  PC  keyboard.   ║");
  133.  
  134. printf("\n\t\t\t╠═════════════════════════════╣");
  135. printf("\n\t\t\t║       KEYBOARD  STATUS      ║");
  136. printf("\n\t\t\t╠═════════════════════════════╣");
  137. do
  138.     {
  139.  
  140.     gotoxy(1,6);
  141.     FINISHED =1;
  142.  
  143.     KEY_WAIT = SUPERQUICK;
  144.  
  145.     if(inkey(PGDN)){FINISHED=0;break;}
  146.     if(inkey(INS_ON))
  147.         printf ("\n\t\t\t║  Insert        STATUS   ON  ║");
  148.     else
  149.         printf ("\n\t\t\t║  Insert        STATUS   OFF ║");
  150.  
  151.  
  152.     if(inkey(CAPSLOCK_ON))
  153.         printf ("\n\t\t\t║  CAPSLOCK      STATUS   ON  ║");
  154.     else
  155.         printf ("\n\t\t\t║  capsLock      STATUS   OFF ║");
  156.  
  157.  
  158.     if(inkey(NUMLOCK_ON))
  159.         printf ("\n\t\t\t║  NumLock       STATUS   ON !║");
  160.     else
  161.         printf ("\n\t\t\t║  NumLock       STATUS   OFF ║");
  162.  
  163.     if(KB101)
  164.     {
  165.     printf("\n\t\t\t╠═════════════════════════════╣");
  166.  
  167.  
  168.     if(inkey(L_CTRL_PRESSED))
  169.         printf ("\n\t\t\t║  Left CTRL     is   PRESSED ║");
  170.     else
  171.         printf ("\n\t\t\t║  Left CTRL     NOT  pressed ║");
  172.  
  173.  
  174.     if(inkey(R_CTRL_PRESSED))
  175.         printf ("\n\t\t\t║  Right CTRL    is   PRESSED ║");
  176.     else
  177.         printf ("\n\t\t\t║  Right CTRL    NOT  pressed ║");
  178.  
  179.  
  180.     if(inkey(L_ALT_PRESSED))
  181.         printf ("\n\t\t\t║  Left ALT      is   PRESSED ║");
  182.     else
  183.         printf ("\n\t\t\t║  Left ALT      NOT  pressed ║");
  184.  
  185.  
  186.     if(inkey(R_ALT_PRESSED))
  187.         printf ("\n\t\t\t║  Right ALT     is   PRESSED ║");
  188.     else
  189.         printf ("\n\t\t\t║  Right ALT     NOT  pressed ║");
  190.  
  191.  
  192.     if(inkey(NUMLOCK_PRESSED))
  193.         printf ("\n\t\t\t║  Numlock       is   PRESSED ║");
  194.     else
  195.         printf ("\n\t\t\t║  Numlock       NOT  pressed ║");
  196.  
  197.  
  198.     if(inkey(SCROLL_PRESSED))
  199.         printf ("\n\t\t\t║  Scroll-Lock   is   PRESSED ║");
  200.     else
  201.         printf ("\n\t\t\t║  Scroll-Lock   NOT  pressed ║");
  202.  
  203.  
  204.     if(inkey(CAPSLOCK_PRESSED))
  205.         printf ("\n\t\t\t║  CapsLock      is   PRESSED ║");
  206.     else
  207.         printf ("\n\t\t\t║  CapsLock      NOT  pressed ║");
  208.  
  209.     }
  210.  
  211.     printf("\n\t\t\t╚═════════════════════════════╝");
  212.  
  213.     printf("\n\n\n\t\t     Press  CTRL-ALT-Q   to exit program");
  214.     printf("\n\t\t     Press  PGDN   to  go to next screen");
  215.  
  216.     KEY_WAIT = QUICK;
  217.  
  218.     /* This loop will continue while NOT CTRL and ALT-Q being pressed  */
  219.  
  220.  
  221.     }while ( ! (inkey(CTRL_PRESSED) && inkey(ALT_Q) )  );
  222.  
  223. return;
  224. }
  225. /* _______________________________________________________________________ */
  226.  
  227.  
  228.  
  229. /* _______________________________________________________________________ */
  230. /* Function to display function key menu for playing sounds with F1 - F12
  231. /* _______________________________________________________________________ */
  232. void fkey_music()
  233. {
  234. unsigned int keyio;
  235. clrscr();
  236. FINISHED=1;
  237.  
  238. printf("\n\n");
  239. printf("\n\t\t     ╔══════════════════════════════════╗");
  240. printf("\n\t\t     ╠══════════════════════════════════╣");
  241. printf("\n\t\t     ║       MUSICAL FUNCTION KEYS      ║");
  242. printf("\n\t\t     ╠══════════════════════════════════╣");
  243. printf("\n\t\t     ╚══════════════════════════════════╝");
  244. printf("\n\n");
  245. printf("\n    ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌");
  246. printf("\n    ▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌");
  247. printf("\n    ▌▌║  F1  ║▌▌▌║  F2  ║▌▌▌║  F3  ║▌▌▌║  F4  ║▌▌▌║  F5  ║▌▌▌║  F6  ║▌▌");
  248. printf("\n    ▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌");
  249. printf("\n    ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌");
  250. printf("\n    ▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌▌╔══════╗▌▌");
  251. printf("\n    ▌▌║  F7  ║▌▌▌║  F8  ║▌▌▌║  F9  ║▌▌▌║  F10 ║▌▌▌║  F11 ║▌▌▌║  F12 ║▌▌");
  252. printf("\n    ▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌▌╚══════╝▌▌");
  253. printf("\n    ▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌");
  254. printf("\n\n\t\t       Press Cntl-Alt-F when Finished");
  255. printf("\n\n\t\t     PGUP - to return to Status Display");
  256. do
  257.     {
  258.  
  259.     KEY_WAIT = FOREVER;
  260.     keyio=(inkey(READ_KEY));
  261.     switch(keyio)
  262.         {
  263.  
  264.         case F1: psound(200,200);
  265.              break;
  266.         case F2: psound(250,200);
  267.              break;
  268.         case F3: psound(300,200);
  269.              break;
  270.         case F4: psound(350,200);
  271.              break;
  272.         case F5: psound(400,220);
  273.              break;
  274.         case F6: psound(450,220);
  275.              break;
  276.         case F7: psound(500,220);
  277.              break;
  278.         case F8: psound(550,220);
  279.              break;
  280.         case F9: psound(600,230);
  281.              break;
  282.         case F10:psound(650,230);
  283.              break;
  284.         case F11:psound(700,230);
  285.              break;
  286.         case F12:psound(750,240);
  287.              break;
  288.         case PGUP:
  289.              break;
  290.  
  291.         }
  292.     if( keyio == (PGUP)){FINISHED=0; break;}
  293.     KEY_WAIT = NORMAL;
  294.  
  295.     /* This loop will continue while NOT CTRL and ALT-F being pressed  */
  296.  
  297.  
  298.     }while ( ! (inkey(CTRL_PRESSED) && inkey(ALT_F) )  );
  299.  
  300. clrscr();
  301. return;
  302. }
  303.